 // 设置当前日期
        document.addEventListener('DOMContentLoaded', function() {
            // 获取当前日期并显示
            const dateOptions = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' };
            const currentDate = new Date().toLocaleDateString('zh-CN', dateOptions);
            document.getElementById('current-date').textContent = currentDate;
            
            // 获取当前登录用户信息
            const users = JSON.parse(localStorage.getItem('registeredUsers')) || [];
            const loginEmail = localStorage.getItem('currentLoginEmail');
            
            // 验证用户是否已登录
            if (!loginEmail) {
                // 如果没有登录信息，跳转到登录页
                window.location.href = 'index.html';
                return;
            }
            
            // 查找当前登录用户
            const currentUser = users.find(user => user.email === loginEmail);
            
            if (currentUser) {
                // 显示用户名到页面各处
                document.getElementById('welcome-username').textContent = currentUser.name;
                document.getElementById('user-display-name').textContent = currentUser.name;
            } else {
                // 如果用户不存在，清除登录状态并跳转到登录页
                localStorage.removeItem('currentLoginEmail');
                window.location.href = 'index.html';
            }
            
            // 用户菜单下拉功能
            const userMenuButton = document.getElementById('user-menu-button');
            const userMenuDropdown = document.getElementById('user-menu-dropdown');
            
            // 点击头像切换菜单显示/隐藏
            userMenuButton.addEventListener('click', function(event) {
                event.stopPropagation(); // 防止事件冒泡
                userMenuDropdown.classList.toggle('hidden');
            });
            
            // 点击页面其他地方关闭菜单
            document.addEventListener('click', function(event) {
                if (!userMenuButton.contains(event.target) && !userMenuDropdown.contains(event.target)) {
                    userMenuDropdown.classList.add('hidden');
                }
            });
            
            // 退出登录功能
            document.getElementById('logout-button').addEventListener('click', function() {
                localStorage.removeItem('currentLoginEmail');
                window.location.href = 'index.html';
            });
                        
            // 移动端菜单切换
            const mobileMenuButton = document.getElementById('mobile-menu-button');
            const mobileMenu = document.getElementById('mobile-menu');
            
            mobileMenuButton.addEventListener('click', function() {
                mobileMenu.classList.toggle('hidden');
            });
        });
       
     document.addEventListener('DOMContentLoaded', function() {
    const video = document.getElementById('main-video');
    const videoPlaceholder = document.getElementById('video-placeholder');
    const videoControls = document.getElementById('video-controls');
    const playVideoBtn = document.getElementById('play-video');
    const videoPlayBtn = document.getElementById('video-play-btn');
    const progressBar = document.getElementById('progress-bar');
    const progressContainer = document.getElementById('progress-container');
    const videoTime = document.getElementById('video-time');
    const videoTitle = document.getElementById('video-title');
    const videoDescription = document.getElementById('video-description');
    const videoItems = document.querySelectorAll('.video-item');
    const speedOptions = document.querySelectorAll('.speed-option');
    const speedDisplay = document.getElementById('speed-display');
    const videoPlayerContainer = document.querySelector('.video-player-container');
    const videoListContainer = document.querySelector('.video-list-container');
    
    let isDragging = false;
    let isExpanded = false;
    
    // 更新播放按钮图标
    function updatePlayButtonIcon() {
        if (video.paused) {
            videoPlayBtn.innerHTML = '<i class="fa fa-play"></i>';
        } else {
            videoPlayBtn.innerHTML = '<i class="fa fa-pause"></i>';
        }
    }
    
    // 格式化时间显示 (秒 -> MM:SS)
    function formatTime(seconds) {
        const minutes = Math.floor(seconds / 60);
        seconds = Math.floor(seconds % 60);
        return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
    }
    
    // 更新进度条和时间显示
    function updateProgress() {
        if (!isNaN(video.duration) && !isDragging) {
            const percent = (video.currentTime / video.duration) * 100;
            progressBar.style.width = `${percent}%`;
            videoTime.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration)}`;
        }
    }
    
    // 通过进度条控制视频进度
    function seek(e) {
        const rect = progressContainer.getBoundingClientRect();
        const pos = (e.clientX - rect.left) / rect.width;
        video.currentTime = pos * video.duration;
        progressBar.style.width = `${pos * 100}%`;
        videoTime.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration)}`;
    }
    
    // 加载并播放指定视频
    function loadAndPlayVideo(videoSrc, title, description, poster) {
        video.src = videoSrc;
        videoTitle.textContent = title;
        videoDescription.textContent = description;
        video.poster = poster;
        
        videoPlaceholder.classList.add('hidden');
        videoControls.classList.remove('hidden');
        video.load();
        video.play();
        updatePlayButtonIcon();
        
        // 如果是在扩展模式，滚动到视频位置
        if (isExpanded) {
            videoPlayerContainer.scrollIntoView({ behavior: 'smooth' });
        }
    }
    
    // 切换视频播放区域扩展状态
    function toggleVideoExpansion() {
        isExpanded = !isExpanded;
        const parentGrid = videoPlayerContainer.parentElement;
        
        if (isExpanded) {
            // 扩展视频区域，隐藏列表
            parentGrid.classList.remove('lg:grid-cols-2');
            parentGrid.classList.add('lg:grid-cols-1');
            videoListContainer.classList.add('hidden');
            
            // 添加返回按钮
            const backButton = document.createElement('button');
            backButton.id = 'back-to-list';
            backButton.className = 'mt-4 text-primary hover:text-primary/80 text-sm font-medium transition-colors';
            backButton.innerHTML = '<i class="fa fa-arrow-left mr-1"></i> 返回视频列表';
            videoPlayerContainer.parentNode.appendChild(backButton);
            
            backButton.addEventListener('click', toggleVideoExpansion);
        } else {
            // 恢复原始布局
            parentGrid.classList.add('lg:grid-cols-2');
            parentGrid.classList.remove('lg:grid-cols-1');
            videoListContainer.classList.remove('hidden');
            
            // 移除返回按钮
            const backButton = document.getElementById('back-to-list');
            if (backButton) {
                backButton.remove();
            }
        }
    }
    
    // 初始视频设置
    const initialVideoSrc = video.querySelector('source').src;
    loadAndPlayVideo(initialVideoSrc, videoTitle.textContent, videoDescription.textContent, video.poster);
    
    // 事件监听
    playVideoBtn.addEventListener('click', function() {
        videoPlaceholder.classList.add('hidden');
        videoControls.classList.remove('hidden');
        video.play();
        updatePlayButtonIcon();
    });
    
    videoPlayBtn.addEventListener('click', function() {
        if (video.paused) {
            video.play();
        } else {
            video.pause();
        }
        updatePlayButtonIcon();
    });
    
    // 进度条拖动控制
    video.addEventListener('timeupdate', updateProgress);
    
    progressContainer.addEventListener('click', seek);
    
    progressContainer.addEventListener('mousedown', function(e) {
        isDragging = true;
        seek(e);
        video.pause();
    });
    
    document.addEventListener('mousemove', function(e) {
        if (isDragging) {
            seek(e);
        }
    });
    
    document.addEventListener('mouseup', function() {
        if (isDragging) {
            isDragging = false;
            video.play();
        }
    });
    
    video.addEventListener('ended', function() {
        updatePlayButtonIcon();
    });
    
    video.addEventListener('click', function() {
        if (video.paused) {
            video.play();
        } else {
            video.pause();
        }
        updatePlayButtonIcon();
    });
    
    // 播放速度控制
    speedOptions.forEach(option => {
        option.addEventListener('click', function(e) {
            e.stopPropagation();
            const speed = parseFloat(this.getAttribute('data-speed'));
            video.playbackRate = speed;
            speedDisplay.textContent = `${speed}x`;
            
            // 高亮当前选中的速度
            speedOptions.forEach(opt => opt.classList.remove('bg-primary/20'));
            this.classList.add('bg-primary/20');
        });
    });
    
    // 右侧视频项点击事件
    videoItems.forEach(item => {
    item.addEventListener('click', function() {
        const videoSrc = this.getAttribute('data-video');
        const title = this.getAttribute('data-title');
        const description = this.getAttribute('data-description');
        const poster = this.getAttribute('data-poster');
        const duration = this.querySelector('.absolute.bottom-2.right-2').textContent;
        
        // 根据视频标题确定跳转的页面
        let targetPage = 'video-features.html'; // 默认页面
        if (title === '账户安全设置教程') {
            targetPage = 'video-security.html';
        } else if (title === '集成服务使用方法') {
            targetPage = 'video-integration.html';
        }
        
        // 构建跳转URL
        const params = new URLSearchParams();
        params.append('src', videoSrc);
        params.append('title', title);
        params.append('desc', description);
        params.append('poster', poster);
        params.append('duration', duration);
        
        // 跳转到对应的视频介绍页面
        window.location.href = `${targetPage}?${params.toString()}`;
    });
});
    // 控制栏显示/隐藏
    let hideControlsTimeout;
    const videoContainer = video.parentElement;
    
    function showControls() {
        videoControls.classList.remove('hidden');
        clearTimeout(hideControlsTimeout);
        
        if (!video.paused) {
            hideControlsTimeout = setTimeout(() => {
                videoControls.classList.add('hidden');
            }, 3000);
        }
    }
    
    videoContainer.addEventListener('mousemove', showControls);
    videoContainer.addEventListener('click', showControls);
    updateAvatar();
    
    // 监听头像更新事件
    window.addEventListener('avatarUpdated', function(e) {
        const headerAvatar = document.getElementById('header-avatar');
        if (headerAvatar) {
            headerAvatar.src = e.detail.avatar;
        }
    });
    
    // 监听本地存储变化（应对多标签页情况）
    window.addEventListener('storage', function(e) {
        if (e.key === 'registeredUsers') {
            updateAvatar();
        }
    });

});
// 新增：更新头像的函数
function updateAvatar() {
    const users = JSON.parse(localStorage.getItem('registeredUsers')) || [];
    const loginEmail = localStorage.getItem('currentLoginEmail');
    const currentUser = users.find(user => user.email === loginEmail);
    
    const headerAvatar = document.getElementById('header-avatar');
    if (currentUser && currentUser.avatar && headerAvatar) {
        headerAvatar.src = currentUser.avatar;
    }
}